"""
example04 - 字典的创建和使用

Author: Administrator
Date: 2024/1/16
"""

# 字面量语法
student1 = {
    'id': 1001,
    'name': '刘一',
    'sex': True,
    'birthday': '1980-11'
}
print(student1)
print(len(student1))
# 遍历字典中的键
for key in student1:
    print(key, student1[key])
print('-' * 20)

# 遍历字典中的值
print(student1.values())
for value in student1.values():
    print(value)
print('-' * 20)

# 遍历字典中的键值对
for key, value in student1.items():
    print(key, value)
print('-' * 20)

# 构造器函数
student2 = dict(id=1001, name='刘一', sex=True, birthday='1980-11')
print(student2)

list1 = [i for i in range(1, 10)]
print(list1)
set1 = {i for i in range(1, 10)}
print(set1)

# 生成式（推导式）语法
dict1 = {i: i ** 2 for i in range(1, 10)}
print(dict1)

# 生成器
gen_obj = (i for i in range(1, 10))
# for value in gen_obj:
#     print(value)
print(next(gen_obj))